﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace DSkinTheme
{
    public partial class FrmMsg : DSkin.Forms.DSkinForm
    {
        private string MsgTitle;
        private string MsgContent;
        public FrmMsg(string msgTitle, string msgContent)
        {
            MsgTitle = msgTitle;
            MsgContent = msgContent;
            InitializeComponent();
        }

        private void FrmMsg_Load(object sender, EventArgs e)
        {
            lblTitle.Text = MsgTitle;
            lblMsg.Text = MsgContent.Length > 30 ? $"{MsgContent.Substring(0, 30)}..." : MsgContent;

            //自定义特效
            #region 从右向左滑入动画
            Opacity = 0;
            Rectangle rect = Screen.PrimaryScreen.WorkingArea;

            int top = 80;// (rect.Height - Height) / 2;
            Location = new Point(rect.Width + Width, top);
            int centerLeft = rect.Width - Width - 120;// (rect.Width  Width) / 2;

            DoEffect(() =>
            {
                if (Left > centerLeft + 4)
                {
                    Opacity = 1 - 1.0 * (Left - centerLeft) / (rect.Width - Width - centerLeft);
                    Left -= ((Left - centerLeft) / 10);
                    return true;
                }
                Opacity = 1;
                ShowShadow = true;
                return false;
            });
            #endregion

            #region 窗体关闭计时
            timerClose.Interval = 2000;
            timerClose.Tick += new EventHandler(timerClose_Tick);
            timerClose.Start();
            #endregion
        }

        private void FrmMsg_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void timerClose_Tick(object sender, EventArgs e)
        {
            timerClose.Stop();
            Close();
        }

        private void FrmMsg_FormClosed(object sender, FormClosedEventArgs e)
        {
            timerClose.Stop();
            timerClose.Dispose();
        }
    }
}
